******************************************************
*Algorithms in the Public Sector. Why context matters*
*Wenzelburger, König, Felfeli, Achtziger**************
*Replication dofile, PADM*****************************
******************************************************
**Dta-file: dataset_study2_PApaper.dta****************
******************************************************

**Figure 2
histogram depvar1 if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, by(treat_pred) freq bin(10)
graph save histo1 , replace
histogram depvar2 if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343 , by(treat_health) freq bin(10)
graph save histo2, replace
graph combine histo1.gph histo2.gph, ycommon


**Table 2: Direct effects

***Predictive Policing: Model 1 and Model 2
reg depvar1 security_pref i.KF02 inst_trust1  princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto mod1
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto mod2

***Skin Cancer Risk: Model 3 and Model 4
reg depvar2 import_health i.KF05 inst_trust2 princ_transp  treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto mod3
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto mod4

***Table2
esttab mod1 mod2 mod3 mod4 using tab1.rtf, b(a2) star (* .05 ** .01) t r2 r



**Figure 3: Marginal effects plots

***Predictive policing
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
margins, at(security_pref =(0 0.33 0.66 1))
marginsplot
graph save margins1, replace

reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
margins, at(inst_trust1 =(0 0.33 0.66 1))
marginsplot
graph save margins2, replace

reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
margins, at(technopho =(0 0.33 0.66 1))
marginsplot
graph save margins3, replace


***Skin cancer risk
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
margins, at(import_health =(0 0.33 0.66 1))
marginsplot
graph save margins4, replace

reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
margins, at(inst_trust2 =(0 0.33 0.66 1))
marginsplot
graph save margins5, replace

reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
margins, at(technopho =(0 0.33 0.66 1))
marginsplot
graph save margins6, replace


***Figure 3 combined margins
graph combine margins1.gph margins2.gph margins3.gph margins4.gph margins5.gph margins6.gph 



***************************
***********ANNEX***********
***************************

**App9: Alternative algo knowledge variables
***Model 1
reg depvar1 security_pref prob_break_norm  inst_trust1  princ_transp treat_predpol technopho algo_knowledge1 extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod9a

***Model 2
reg depvar1 security_pref prob_break_norm  inst_trust1  princ_transp treat_predpol technopho algo_knowledge2 extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod9b

***Model 3
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge1 extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod9c

***Model 4
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge2 extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod9d

***Table Annex A9
esttab appmod9a appmod9b appmod9c appmod9d using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r


**App10: Binary algo knowledge variable
***Model 1
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_bin extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod10a

***Model 2
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_bin extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod10b

***Table Annex A10
esttab appmod10a appmod10b using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r


**App11: Expert knowledge variables
***Model 1
reg depvar1 security_pref prob_break_norm  inst_trust1  princ_transp treat_predpol technopho knowledge1_pred extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod11a

***Model 2
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho knowledge1_med extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod11b

***Table Annex A11
esttab appmod11a appmod11b using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r

**App12: Alternative health importance variables
***Model 1
reg depvar2 import_health prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod12a

***Model 2
reg depvar2 import_health2  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
est sto appmod12b

***Table Annex A12
esttab appmod12a appmod12b using tab3.rtf, b(a2) star (* .05 ** .01) t r2 r


**App13 - Robustness check with and wo control questions

***Predictive Policing
****Model 1
reg depvar1 security_pref i.KF02 inst_trust1  princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 , vce(rob) //only attention check
est sto mod1
****Model 2
reg depvar1 security_pref i.KF02 inst_trust1  princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 , vce(rob) //att check plus control
est sto mod2
****Model 3
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1, vce(rob) //only attention check
est sto mod3
***Model 4
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1, vce(rob) //att check plus control
est sto mod4
****Table Annex A13, first part (Predictive Policing)
esttab mod1 mod2 mod3 mod4 using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r

**Skin Cancer Risk
****Model 1
reg depvar2 import_health i.KF05 inst_trust2 princ_transp  treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 , vce(rob) //only att check
est sto mod1
****Model 2
reg depvar2 import_health i.KF05 inst_trust2 princ_transp  treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 , vce(rob)
//att check plus control
est sto mod2
****Model 3
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1, vce(rob) //only att check
est sto mod3
****Model 4
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1, vce(rob) //att check plus control
est sto mod4
****Table Annex A13, second part (Skin Cancer Risk)
esttab mod1 mod2 mod3 mod4 mod5 mod6 using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r


***App14 - Speeding Check: Median split by time intro/examples (context == 0 --> depvar1)
****context-variable: without missings on DV1 and DV2, CS16 with missings in DV1 and DV2

****Check Filter Variables and descriptives
summarize TIME_INTRO if context==0 & TE01_14 ==1 & KO01 == 1, det //DV1
summarize TIME_AFTERCON if context==0 & TE01_14 ==1 & KO01 == 1, det //DV1

summarize TIME_INTRO if context==1 & TE01_14 ==1 & KO01 == 1, det //DV2
summarize TIME_AFTERCON if context==1 & TE01_14 ==1 & KO01 == 1, det //DV2

summarize TIME_INTRO if CS16 < 3 & TE01_14 ==1 & KO01 == 1, det //DV1
summarize TIME_AFTERCON if CS16 < 3 & TE01_14 ==1 & KO01 == 1, det //DV1

summarize TIME_INTRO if CS16 > 2 & TE01_14 ==1 & KO01 == 1, det //DV2
summarize TIME_AFTERCON if CS16 > 2 & TE01_14 ==1 & KO01 == 1, det //DV2

****Predictive policing - Check
reg depvar1 security_pref i.KF02 inst_trust1  princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343 , vce(rob)
summarize TIME_INTRO if e(sample), det
summarize TIME_AFTERCON if e(sample), det

reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
summarize TIME_INTRO if e(sample), det
summarize TIME_AFTERCON if e(sample), det

****Skin cancer risk - Check
reg depvar2 import_health i.KF05 inst_trust2 princ_transp  treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
summarize TIME_INTRO if e(sample), det
summarize TIME_AFTERCON if e(sample), det

reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_SUM > 110.32 & TIME_SUM < 1222.2343, vce(rob)
summarize TIME_INTRO if e(sample), det
summarize TIME_AFTERCON if e(sample), det


****Regression models with different speeding checks, Annex A14
****Model 1
reg depvar1 security_pref i.KF02 inst_trust1  princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_INTRO >33 , vce(rob)
est sto mod1
****Model 2
reg depvar1 security_pref i.KF02 inst_trust1  princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_AFTERCON >171.5 , vce(rob)
est sto mod2
****Model 3
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_INTRO >32, vce(rob)
est sto mod3
****Model 4
reg depvar1 security_pref  prob_break_norm  inst_trust1 princ_transp treat_predpol technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar1 education_new if TE01_14 ==1 & KO01 == 1 & TIME_AFTERCON > 171, vce(rob)
est sto mod4
esttab mod1 mod2 mod3 mod4 using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r

****Model 5
reg depvar2 import_health i.KF05 inst_trust2 princ_transp  treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_INTRO > 21, vce(rob)
est sto mod1
****Model 6
reg depvar2 import_health i.KF05 inst_trust2 princ_transp  treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_AFTERCON > 163 , vce(rob)
est sto mod2
****Model 7
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_INTRO > 21, vce(rob)
est sto mod3
****Model 8
reg depvar2 import_health  prob_sick_norm  inst_trust2 princ_transp treat_health technopho algo_knowledge_sum extrav agreeab conscien openn neuro female age_depvar2 education_new  if TE01_14 ==1 & KO01 == 1 & TIME_AFTERCON > 160, vce(rob)
est sto mod4


esttab mod1 mod2 mod3 mod4 using tab2.rtf, b(a2) star (* .05 ** .01) t r2 r
